/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Ads_Task",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using DGZImp.AdsProject.DomainModels;
using DGZImp.AdsProject.IServices;
using DGZImp.Core.Utilities.Response;

namespace DGZImp.AdsProject.Controllers
{
    public partial class Ads_TaskController
    {
        private readonly IAds_TaskService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public Ads_TaskController(
            IAds_TaskService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }

        /// <summary>
        /// 新增和修改异常任务
        /// </summary>
        /// <param name="Dto"></param>
        /// <returns></returns>
        [HttpPost("AddOrUpdate")]
        public async Task<ApiResponse<long>> AddOrUpdate([FromBody] AbnormalTaskDto Dto)
        {
            var res = await _service.AddOrUpdate(Dto);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 获取异常任务分页数据
        /// </summary>
        /// <param name="Dto"></param>
        /// <returns></returns>
        [HttpPost("Page")]
        public async Task<ApiResponse<AbnormalTaskPageOutDto>> Page([FromBody] AbnormalTaskPageInDto Dto)
        {
            var res = await _service.GetPage(Dto);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 获取异常任务详情
        /// </summary>
        /// <param name="AbnormalTaskId"></param>
        /// <returns></returns>
        [HttpGet("GetDetail")]
        public async Task<ApiResponse<AbnormalTaskDto>> GetDetail(long AbnormalTaskId)
        {
            var res = await _service.GetDetail(AbnormalTaskId);
            return ApiRes.Success(res);
        }

        /// <summary>
        /// 获取异常任务日志
        /// </summary>
        /// <param name="AbnormalTaskId"></param>
        /// <returns></returns>
        [HttpGet("GetTaskLog")]
        public async Task<ApiResponse<List<TaskLogDto>>> GetTaskLog(long TaskId)
        {
            var res = await _service.GetTaskLog(TaskId);
            return ApiRes.Success(res);
        }
    }
}
